#include <iostream>
#include <vector>
#include "geometry.h"

int main()
{
   int n;
   std::cin >> n;
   std::vector<point> points;
   for (int i = 0; i < n; i++)
   {
      double x, y;
      std::cin >> x >> y;
      points.push_back(point(x, y));
   }
   kd2tree tree = kd2tree(points);

   int m;
   std::cin >> m;
   std::cout.precision(20);
   for (int i = 0; i < m; i++)
   {
      double x1, y1, x2, y2;
      std::cin >> x1 >> y1 >> x2 >> y2;

      std::vector<point> res = tree.find_points(point(x1, y1), point(x2, y2));
      int k = res.size();
      std::cout << k << "\n";
      for (int j = 0; j < k; j++)
      {
         std::cout << res[j].x << " " << res[j].y << "\n";
      }
   }
   return 0;
}